package cn.jzq.kotoba.modules.designpattern.observer.weather.demo1;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public  abstract  class Observable {

    protected List<Observer> observers;

    public Observable() {
        this.observers = new CopyOnWriteArrayList<>();
    }

    public void addObserver(Observer observer) {
        this.observers.add(observer);
    }

    public void removeObserver(Observer observer) {
        this.observers.remove(observer);
    }

    public void notifyObservers(Object arg) {
        for (Observer observer: observers) {
            observer.update(arg);
        }
    }

}
